package gladrag;

import javax.swing.JOptionPane;

public class Fan implements Observer, DisplayElement {

	private String name;
	private String latestNews;
	private Star follows;
	
	public Fan(String name, Star follows) {
		setName(name);
		setFollows(follows);
	}
	
	private void setName(String name) {
		this.name = name;
	}
	
	private void setFollows(Star follows) {
		this.follows = follows;
		this.follows.registerObserver(this);
	}
	
	@Override
	public void display() {
		String output = "News for "+this.name+"\n";
		output += this.latestNews;
		JOptionPane.showMessageDialog(null, output, "", JOptionPane.INFORMATION_MESSAGE);
	}

	@Override
	public void update(String news) {
		this.latestNews = news;
		display();
	}

}
